/* 
获取文件树的映射
*/
export default function mapping(rootDir) {
  const tree = {}
  const read = (rootdir) => {
    fs.readdirSync(rootdir).forEach(item => {
      const dir = path.resolve(rootdir, item)
      const stat = fs.statSync(dir)
      if (!stat) {
        return
      }
      if (stat.isDirectory()) {
        read(dir)
      } else if (stat.isFile()) {
        import(dir).then(modules => {
          tree[path.basename(dir, '.js')] = modules
        }).catch(err => {
          console.log(`${dir}，读取失败！`)
        })
      }
    })
  }
  read(rootDir)
  return tree
}

// mapping(path.resolve(__dirname, './api'))